#include "conditioneditdialog.h"
#include "ui_conditioneditdialog.h"
#include"sourcemanage.h"

ConditionEditDialog::ConditionEditDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConditionEditDialog)
{
    ui->setupUi(this);
    ui->comboBox_1->addItems(SM->options.value("SymbleType"));
    ui->comboBox_2->addItems(SM->options.value("SymbleType"));
    ui->comboBox_3->addItems(SM->options.value("SymbleType"));
    ui->comboBox_4->addItems(SM->options.value("SymbleType"));
    ui->comboBox_5->addItems(SM->options.value("SymbleType"));
    ui->comboBox_6->addItems(SM->options.value("SymbleType"));
    ui->comboBox_7->addItems(SM->options.value("SymbleType"));

    connect(ui->pushButton_Cancel,SIGNAL(clicked()),this,SLOT(close()));
}

ConditionEditDialog::~ConditionEditDialog()
{
    delete ui;
}

void ConditionEditDialog::SaveData()
{

}

void ConditionEditDialog::LoadData(QList<WorkStepCondition> conditions)//
{
    if(conditions.count()<7) return;//
    int i=0;
    ui->checkBox_1->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_1->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_1->setValue(conditions.at(i++).value);
    ui->checkBox_2->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_2->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_2->setValue(conditions.at(i++).value);
    ui->checkBox_3->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_3->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_3->setValue(conditions.at(i++).value);
    ui->checkBox_4->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_4->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_4->setValue(conditions.at(i++).value);
    ui->checkBox_5->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_5->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_5->setValue(conditions.at(i++).value);
    ui->checkBox_6->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_6->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_6->setValue(conditions.at(i++).value);
    ui->checkBox_7->setChecked(conditions.at(i).bIsChoose);
    ui->comboBox_7->setCurrentIndex(conditions.at(i).index);
    ui->doubleSpinBox_7->setValue(conditions.at(i++).value);
}

QList<WorkStepCondition> ConditionEditDialog::GetData()
{
    QList<WorkStepCondition> conditions;
    WorkStepCondition condition;
    conditions.append(condition);
    conditions.append(condition);
    conditions.append(condition);
    conditions.append(condition);
    conditions.append(condition);
    conditions.append(condition);
    conditions.append(condition);

    int i=0;
    conditions[i].bIsChoose=ui->checkBox_1->isChecked();
    conditions[i].index=ui->comboBox_1->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_1->value();
    conditions[i].bIsChoose=ui->checkBox_2->isChecked();
    conditions[i].index=ui->comboBox_2->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_2->value();
    conditions[i].bIsChoose=ui->checkBox_3->isChecked();
    conditions[i].index=ui->comboBox_3->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_3->value();
    conditions[i].bIsChoose=ui->checkBox_4->isChecked();
    conditions[i].index=ui->comboBox_4->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_4->value();
    conditions[i].bIsChoose=ui->checkBox_5->isChecked();
    conditions[i].index=ui->comboBox_5->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_5->value();
    conditions[i].bIsChoose=ui->checkBox_6->isChecked();
    conditions[i].index=ui->comboBox_6->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_6->value();
    conditions[i].bIsChoose=ui->checkBox_7->isChecked();
    conditions[i].index=ui->comboBox_7->currentIndex();
    conditions[i++].value=ui->doubleSpinBox_7->value();

    return conditions;
}
void ConditionEditDialog::on_pushButton_Ok_clicked()
{
    //check
    //save
    this->accept();
    //close();
}
